<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<c:import url="../cabecalho.jsp" />
<c:import url="../menu.jsp" />
<div class="col-sm-9 col-sm-offset-3 col-lg-10 col-lg-offset-2 main">
	<div class="row">
		<ol class="breadcrumb">
			<li>
				<a href="#">
					<span class="glyphicon glyphicon-home"></span>
				</a>
			</li>
			<li class="active">
				<fmt:message key="pedido.pecas.ow" />
			</li>
		</ol>
	</div>
	<div class="row">
		<div class="col-lg-12">
			<h1 class="page-header">
				<fmt:message key="pedido.pecas.ow" />
			</h1>
		</div>
	</div>
	
		<div class="row">
			<div class="col-lg-10 col-md-10">
				<div class="panel panel-default">
					<div class="panel-heading cab">
						<fmt:message key="pedido.pecas.ow.fora.garantia" />
					</div>
					<div class="panel-body">
					<form:form action="adicionaPecaAoPedido" commandName="pedidoPeca">
						<c:if test="${not empty msg && msg.tipo eq 'sucesso'}">
							<div class="alert alert-success" role="alert">
								<fmt:message key="${msg.texto}" />
							</div>
						</c:if>
						<c:if test="${not empty msg && msg.tipo eq 'erro'}">
							<div class="alert alert-danger" role="alert">
								<b>
									<fmt:message key="${msg.texto}">
										<br>
									</fmt:message>
								</b>
								<form:errors path="peca.codigo" cssStyle="color:black; display: block;" />
								<form:errors path="quantidade" cssStyle="color:black; display: block;" />
							</div>
						</c:if>
						<div class="col-md-12 col-lg-12">
							<div class="form-group col-md-6 col-lg-6">
								<form:label path="peca.codigo">
									<fmt:message key="codigo" />
								</form:label>
								<input type="text" class="form-control" name="peca.codigo" id="codigoDaPecaAutocomplete" value="" placeholder="<fmt:message key="codigo.descricao" />">
							</div>
							<div class="form-group col-md-4 col-lg-4">
								<form:label path="quantidade">
									<fmt:message key="quantidade" />
								</form:label>
								<form:input path="quantidade" type="number" cssClass="form-control required" />
							</div>
							<div class="form-group col-md-2 col-lg-2">
								<button type="submit" class="btn btn-primary direita">
									<fmt:message key="incluir" />
								</button>
							</div>
						</div>
					</form:form>
					<form:form action="gravarPedido" commandName="pedido">
						<c:if test="${not empty pedido.pedidosPeca}">
							<div class="col-lg-12">
								<table class="table table-hover">
									<thead>
										<tr>
											<th>
												<fmt:message key="codigo" />
											</th>
											<th>
												<fmt:message key="descricao" />
											</th>
											<th>
												<fmt:message key="disponibilidade" />
											</th>
											<th>
												<fmt:message key="preco" />
											</th>
											<th>
												<fmt:message key="quantidade" />
											</th>
											<th>
												<fmt:message key="precototal" />
											</th>
										</tr>
									</thead>
									<c:forEach items="${pedido.pedidosPeca}" var="pedidoPeca">
										<tr>
											<td>${pedidoPeca.peca.codigo}</td>
											<td>${pedidoPeca.peca.descricao}</td>
											<td>${pedidoPeca.peca.disponibilidade}</td>
											<td><fmt:formatNumber value="${pedidoPeca.peca.preco}" minFractionDigits="2" type="currency"/></td>
											<td>${pedidoPeca.quantidade}</td>
											<td><fmt:formatNumber value="${pedidoPeca.precoTotal}" minFractionDigits="2" type="currency"/></td>
										</tr>
									</c:forEach>
									<tfoot>
										<tr>
											<td>
												<b><fmt:message key="dados.fechamento.pedidoemgarantia.total" /></b>
											</td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											<td><b><fmt:formatNumber value="${pedido.precoTotal}" minFractionDigits="2" type="currency"/></b></td>
										</tr>
									</tfoot>
								</table>
							</div>
							<div class="col-md-12 col-lg-12">
								<div class="form-group col-md-12 col-lg-12">
									<button type="submit" class="btn btn-primary direita">
										<fmt:message key="fazer.pedido" />
									</button>
								</div>
							</div>
						</c:if>
					</form:form>
				</div>
				</div>
			</div>
		</div>
		<form:input type="hidden" path="pedido" />
		<input type="hidden" name="temErroForm" id="temErroForm" value="${not empty msg && msg.tipo eq 'erro' ? 'sim' : 'nao'}" />
</div>


<c:import url="../rodape.jsp" />
